package org.carl.base.dingtalk.bot.config;

import org.carl.base.dingtalk.bot.annotation.EnableDingTalkbot;
import org.carl.base.dingtalk.bot.aspectj.DingTalkNotifyAspect;
import org.carl.base.dingtalk.bot.bean.DingTalkRobot;
import org.carl.base.dingtalk.bot.service.DingTalkService;
import org.carl.base.dingtalk.bot.service.impl.DingTalkServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 钉钉配置
 *
 * @author Carl
 */
@ConditionalOnBean(annotation = EnableDingTalkbot.class)
@Configuration
public class DingTalkConfig {

    @Bean
    @ConfigurationProperties("carl.dingtalk")
    public DingTalkRobot dingtalkRobot() {
        return new DingTalkRobot();
    }

    @Bean
    @ConditionalOnBean(DingTalkRobot.class)
    public DingTalkService dingTalkService() {
        return new DingTalkServiceImpl();
    }

    @Bean
    @ConditionalOnBean(DingTalkRobot.class)
    public DingTalkNotifyAspect dingTalkNotifyAspect() {
        return new DingTalkNotifyAspect();
    }
}
